import {Component, Input, OnInit} from '@angular/core';
import {BakeProPlan} from '../../../../model/ProPlan';
import {AdminService} from "../../../../services/admin.service";
import {AlertService} from "../../../../services/alert.service";

@Component({
  selector: 'app-produceplanedit',
  templateUrl: './produceplanedit.component.html',
  styleUrls: ['./produceplanedit.component.css']
})
export class ProduceplaneditComponent implements OnInit {
  @Input()optype:string;
  @Input()id:string;

  p:BakeProPlan;
  constructor(private adminService:AdminService,
              private alertService:AlertService) {
    this.p=new BakeProPlan();
  }

  ngOnInit(): void {
    if(this.optype=="update"){
      this.getProductByid()
    }
  }
  getProductByid(){
    this.adminService.getProplanByid(this.id).then((data:any)=>{
      if(data.msg == "ok"){
        this.p = data.obj
      }else{
        this.alertService.showError("根据id获取生产计划失败")
      }
    })
  }
  save(){
    this.adminService.saveProplan(this.p).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("根据id获取生产计划成功")
      }else{
        this.alertService.showError("根据id获取生产计划失败")
      }
    })
  }

}
